

<!DOCTYPE html>
<html class="writer-html5" lang="en" data-content_root="../">
<head>
  <meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Sharepoint &mdash; O365  documentation</title>
      <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />
      <link rel="stylesheet" type="text/css" href="../_static/css/theme.css?v=e59714d7" />

  
      <script src="../_static/jquery.js?v=5d32c60e"></script>
      <script src="../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
      <script src="../_static/documentation_options.js?v=5929fcd5"></script>
      <script src="../_static/doctools.js?v=9bcbadda"></script>
      <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
    <script src="../_static/js/theme.js"></script>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="Tasks" href="tasks.html" />
    <link rel="prev" title="Planner" href="planner.html" />
    <link href="../_static/css/style.css" rel="stylesheet" type="text/css">

</head>

<body class="wy-body-for-nav"> 
  <div class="wy-grid-for-nav">
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >

          
          
          <a href="../index.html">
            
          </a>
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>
        </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
              <p class="caption" role="heading"><span class="caption-text">Contents:</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../overview.html">Overview</a></li>
<li class="toctree-l1"><a class="reference internal" href="../getting_started.html">Getting Started</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../usage.html">Detailed Usage</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="connection.html">Protocols</a></li>
<li class="toctree-l2"><a class="reference internal" href="connection.html#resources">Resources</a></li>
<li class="toctree-l2"><a class="reference internal" href="account.html">Account</a></li>
<li class="toctree-l2"><a class="reference internal" href="account.html#account-class-and-modularity">Account Class and Modularity</a></li>
<li class="toctree-l2"><a class="reference internal" href="addressbook.html">Address Book</a></li>
<li class="toctree-l2"><a class="reference internal" href="calendar.html">Calendar</a></li>
<li class="toctree-l2"><a class="reference internal" href="directory.html">Directory and Users</a></li>
<li class="toctree-l2"><a class="reference internal" href="excel.html">Excel</a></li>
<li class="toctree-l2"><a class="reference internal" href="group.html">Group</a></li>
<li class="toctree-l2"><a class="reference internal" href="mailbox.html">Mailbox</a></li>
<li class="toctree-l2"><a class="reference internal" href="onedrive.html">OneDrive</a></li>
<li class="toctree-l2"><a class="reference internal" href="planner.html">Planner</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">Sharepoint</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#sharepoint-lists">Sharepoint Lists</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#sharepoint-list-items">Sharepoint List Items</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="tasks.html">Tasks</a></li>
<li class="toctree-l2"><a class="reference internal" href="teams.html">Teams</a></li>
<li class="toctree-l2"><a class="reference internal" href="utils.html">Utils</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../api.html">O365 API</a></li>
</ul>

        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../index.html">O365</a>
      </nav>

      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="Page navigation">
  <ul class="wy-breadcrumbs">
      <li><a href="../index.html" class="icon icon-home" aria-label="Home"></a></li>
          <li class="breadcrumb-item"><a href="../usage.html">Detailed Usage</a></li>
      <li class="breadcrumb-item active">Sharepoint</li>
      <li class="wy-breadcrumbs-aside">
            <a href="../_sources/usage/sharepoint.rst.txt" rel="nofollow"> View page source</a>
      </li>
  </ul><div class="rst-breadcrumbs-buttons" role="navigation" aria-label="Sequential page navigation">
        <a href="planner.html" class="btn btn-neutral float-left" title="Planner" accesskey="p"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
        <a href="tasks.html" class="btn btn-neutral float-right" title="Tasks" accesskey="n">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
  </div>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
             
  <section id="sharepoint">
<h1>Sharepoint<a class="headerlink" href="#sharepoint" title="Link to this heading"></a></h1>
<p>These are the scopes needed to work with the SharePoint and Site classes.</p>
<table class="docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p>Raw Scope</p></th>
<th class="head"><p>Included in Scope Helper</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>Sites.Selected</p></td>
<td><p><em>None</em></p></td>
<td><p>Sites a permission was granted by admins (see <a class="reference external" href="https://github.com/O365/python-o365/issues/1122">https://github.com/O365/python-o365/issues/1122</a>)</p></td>
</tr>
<tr class="row-odd"><td><p>Sites.Read.All</p></td>
<td><p>sharepoint</p></td>
<td><p>To only read sites, lists and items</p></td>
</tr>
<tr class="row-even"><td><p>Sites.ReadWrite.All</p></td>
<td><p>sharepoint_dl</p></td>
<td><p>To read and save sites, lists and items</p></td>
</tr>
</tbody>
</table>
<p>Note that using the <code class="code docutils literal notranslate"><span class="pre">.All</span></code> scopes is way less secure than granting permissions to specific sites and using
<code class="code docutils literal notranslate"><span class="pre">Sites.Selected</span></code> scope.</p>
<p>Assuming an authenticated account, create a Sharepoint instance, and connect
to a Sharepoint site.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1">#Create Sharepoint instance and connect to a site</span>
<span class="kn">from</span><span class="w"> </span><span class="nn">O365</span><span class="w"> </span><span class="kn">import</span> <span class="n">Account</span>
<span class="n">acct</span> <span class="o">=</span> <span class="n">Account</span><span class="p">((</span><span class="s1">&#39;app_id&#39;</span><span class="p">,</span> <span class="s1">&#39;app_pw&#39;</span><span class="p">))</span>
<span class="n">sp_site</span> <span class="o">=</span> <span class="n">acct</span><span class="o">.</span><span class="n">sharepoint</span><span class="p">()</span><span class="o">.</span><span class="n">get_site</span><span class="p">(</span><span class="s1">&#39;root&#39;</span><span class="p">,</span> <span class="s1">&#39;path/tosite&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>Common commands for <code class="code docutils literal notranslate"><span class="pre">sp_site</span></code> include <code class="code docutils literal notranslate"><span class="pre">.display_name</span></code>,
<code class="code docutils literal notranslate"><span class="pre">.get_document_library()</span></code>, <code class="code docutils literal notranslate"><span class="pre">.get_subsites()</span></code>, <code class="code docutils literal notranslate"><span class="pre">.get_lists()</span></code>,
and <code class="code docutils literal notranslate"><span class="pre">.get_list_by_name('list_name')</span></code>.</p>
<p><strong>Accessing Subsites</strong></p>
<p>If a Sharepoint site contains subsites they can be returned as a list of
Sharepoint sites by the <code class="code docutils literal notranslate"><span class="pre">.get_subsites()</span></code> function.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1">#Return a List of subsites</span>
<span class="n">sp_site_subsites</span> <span class="o">=</span> <span class="n">sp_site</span><span class="o">.</span><span class="n">get_subsites</span><span class="p">()</span>
<span class="nb">print</span><span class="p">(</span><span class="n">sp_sites_subsites</span><span class="p">)</span>
<span class="p">[</span><span class="n">Site</span><span class="p">:</span> <span class="n">subsitename1</span><span class="p">,</span> <span class="n">Site</span><span class="p">:</span> <span class="n">subsitename2</span><span class="p">]</span>

<span class="c1">#Make another Site object from a desired subsite</span>
<span class="n">new_sp_site</span> <span class="o">=</span> <span class="n">sp_site_subsites</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="c1">#return the first subsite</span>
</pre></div>
</div>
<section id="sharepoint-lists">
<h2>Sharepoint Lists<a class="headerlink" href="#sharepoint-lists" title="Link to this heading"></a></h2>
<p>Sharepoint Lists are accessible from their Sharepoint site using <code class="code docutils literal notranslate"><span class="pre">.get_lists()</span></code> which
returns a Python list of Sharepoint list objects.  A known list can be accessed
by providing a <code class="code docutils literal notranslate"><span class="pre">list_name</span></code> to <code class="code docutils literal notranslate"><span class="pre">.get_list_by_name('list_name')</span></code> which will return
the requested list as a <code class="code docutils literal notranslate"><span class="pre">sharepointlist</span></code> object.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1">#Return a list of sharepoint lists</span>
<span class="n">sp_site_lists</span> <span class="o">=</span> <span class="n">sp_site</span><span class="o">.</span><span class="n">get_lists</span><span class="p">()</span>

<span class="c1">#Return a specific list by name</span>
<span class="n">sp_list</span> <span class="o">=</span> <span class="n">sp_site</span><span class="o">.</span><span class="n">get_list_by_name</span><span class="p">(</span><span class="s1">&#39;list_name&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>Commmon functions on a Sharepoint list include <code class="code docutils literal notranslate"><span class="pre">.get_list_columns()</span></code>,
<code class="code docutils literal notranslate"><span class="pre">.get_items()</span></code>, <code class="code docutils literal notranslate"><span class="pre">.get_item_by_id()</span></code>, <code class="code docutils literal notranslate"><span class="pre">.create_list_item()</span></code>,
<code class="code docutils literal notranslate"><span class="pre">.delete_list_item()</span></code>.</p>
<section id="sharepoint-list-items">
<h3>Sharepoint List Items<a class="headerlink" href="#sharepoint-list-items" title="Link to this heading"></a></h3>
<p>Accessing a list item from a Sharepoint list is done by utilizing <code class="code docutils literal notranslate"><span class="pre">.get_items()</span></code>,
or <code class="code docutils literal notranslate"><span class="pre">.get_item_by_id(item_id)</span></code>.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1">#Return a list of sharepoint list Items</span>
<span class="n">sp_list_items</span> <span class="o">=</span> <span class="n">sp_list</span><span class="o">.</span><span class="n">get_items</span><span class="p">()</span>

<span class="c1">#Return a specific sharepoint list item by its object ID</span>
<span class="n">sp_list_item</span> <span class="o">=</span> <span class="n">sp_list</span><span class="o">.</span><span class="n">get_item_by_id</span><span class="p">(</span><span class="n">item_id</span><span class="p">)</span>
</pre></div>
</div>
<p><strong>Creating &amp; Deleting Sharepoint Items</strong></p>
<p>A Sharepoint list item can be created by passing the new data in a dictionary
consisting of <code class="code docutils literal notranslate"><span class="pre">{'column_name':</span> <span class="pre">'new_data'}</span></code>.  Not all columns in the Sharepoint list have to
be accounted for in the dictionary, any Sharepoint List column not in the dictionary
will be filled with a blank.  The <cite>column_name</cite> must be the internal column name
of the sharepoint list.  <code class="code docutils literal notranslate"><span class="pre">.column_name_cw</span></code> of a sharepoint list will provide a
dictionary of <code class="code docutils literal notranslate"><span class="pre">{'Display</span> <span class="pre">Name':</span> <span class="pre">'Internal</span> <span class="pre">Name'}</span></code> if needed.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1">#Create a new sharepoint list item</span>
<span class="n">new_item</span> <span class="o">=</span> <span class="n">sp_list</span><span class="o">.</span><span class="n">create_list_item</span><span class="p">({</span><span class="s1">&#39;col1&#39;</span><span class="p">:</span> <span class="s1">&#39;New Data Col 1&#39;</span><span class="p">,</span>
                                     <span class="s1">&#39;col2&#39;</span><span class="p">:</span> <span class="s1">&#39;New Data Col 2&#39;</span><span class="p">})</span>

<span class="c1">#Delete the item just created</span>
<span class="n">sp_list</span><span class="o">.</span><span class="n">delete_list_item</span><span class="p">(</span><span class="n">new_item</span><span class="o">.</span><span class="n">object_id</span><span class="p">)</span>  <span class="c1">#Pass the item ID to be deleted</span>
</pre></div>
</div>
<p><strong>Updating a Sharepoint List Item</strong></p>
<p>Sharepoint list items can be updated by passing a dictionary of
<code class="code docutils literal notranslate"><span class="pre">{'column_name':</span> <span class="pre">'Updated</span> <span class="pre">Data'}</span></code> to the <code class="code docutils literal notranslate"><span class="pre">.update_fields()</span></code> function of a
Sharepoint list item.  The <cite>column_name</cite> keys of the dictionary must again refer
to the internal column name, otherwise an error will occur.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1">#Update a Sharepoint List item</span>
<span class="n">new_item</span><span class="o">.</span><span class="n">update_fields</span><span class="p">({</span><span class="s1">&#39;col1&#39;</span><span class="p">:</span> <span class="s1">&#39;Updated Data Col1&#39;</span><span class="p">,</span>
                        <span class="s1">&#39;col2&#39;</span><span class="p">:</span> <span class="s1">&#39;Updated Data Col2&#39;</span><span class="p">})</span>

<span class="c1">#Once done updating a sharepoint item save changes to the cloud</span>
<span class="n">new_item</span><span class="o">.</span><span class="n">save_updates</span><span class="p">()</span> <span class="c1">#Returns True if successful</span>
</pre></div>
</div>
</section>
</section>
</section>


           </div>
          </div>
          <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
        <a href="planner.html" class="btn btn-neutral float-left" title="Planner" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
        <a href="tasks.html" class="btn btn-neutral float-right" title="Tasks" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>&#169; Copyright 2025, alejcas.</p>
  </div>

  Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    provided by <a href="https://readthedocs.org">Read the Docs</a>.
   

</footer>
        </div>
      </div>
    </section>
  </div>
  <script>
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>